package com.example.administrator.nurse.model.adapter;

import android.content.Context;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * Created by Administrator on 2016/1/28.
 */
public abstract class CommonAdapter<T> extends BaseAdapter {
    private List<T> mDatas;
    private int LayoutId;
    private Context context;

    public CommonAdapter(List mDatas,int layoutId,Context context){
        this.mDatas=mDatas;
        this.context=context;
        this.LayoutId=layoutId;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    public List<T> getList(){
        return mDatas;
    }

    public void addBeanAtStart(T data){
        mDatas.add(0,data);
        notifyDataSetChanged();
    }
    public void addBeanAtEnd(T data){
        mDatas.add(data);
        notifyDataSetChanged();
    }
    public void addListAtStart(List datas){
        mDatas.addAll(0, datas);
        notifyDataSetChanged();
    }
    public void addListAtEnd(List datas){
        mDatas.addAll(datas);
        notifyDataSetChanged();
    }
    public void remove(int position){
        if (mDatas!=null&&position<mDatas.size()&&position>=0)
        mDatas.remove(position);
        notifyDataSetChanged();
    }
    public void remove(T data){
        mDatas.remove(data);
        notifyDataSetChanged();
    }
    public void removeAll(){
        if(mDatas!=null){
            mDatas.clear();
            notifyDataSetChanged();
        }
    }
    public void replaceBean(int position,T data){
        mDatas.remove(position);
        mDatas.add(position,data);
    }
}
